package com.examples.gateway.listener;

import com.examples.core.req.ExamHeader;
import com.examples.gateway.entity.SystemOperateLog;
import com.examples.gateway.service.OperateLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @ClassName: OperateLogListener
 * @Description: TODO
 * @Author: DAIYALU
 * @Date: 2024/6/20
 * @Version: 1.0
 */
@Component
@RequiredArgsConstructor
public class OperateLogListener  {

    private final OperateLogService operateLogService;

    @EventListener
    public void saveLogEvent(OperateLogEvent event) {
        ExamHeader header = new ExamHeader();
        header.setUserId(event.getUserId());
        SystemOperateLog log = new SystemOperateLog();
        log.setUserId(event.getUserId());
        log.setUserType(event.getUserType());
        log.setMenuCode(event.getMenuCode());
        log.setServiceName(event.getServiceName());
        log.setRequestMethod(event.getRequestMethod());
        log.setRequestUrl(event.getRequestUrl());
        log.setUserIp(event.getUserIp());
        log.setStartTime(event.getStartTime());
        log.setDuration(event.getDuration().intValue());
        log.setResultCode(event.getResultCode());
        operateLogService.saveLog(header,log);
    }

}
